package org.gd.hellojaxb.privat24.ekb.connectors;

public class EKBCon {

    public static String getUserInfoEKBRequest(String ekb_id, String userInn, String userPhone) {
        StringBuilder req = new StringBuilder();
        req.append("<?xml version='1.0' encoding='UTF-8'?>");
        req.append("<doc>");
        //req.append("<r cntr='UA' ").append(getProminSessionIdString()).append("  key='1' t='LST'>");

        if (!nullOrEmpty(ekb_id)) {
            req.append("<i Id='").append(ekb_id).append("' />");
        } else if (!nullOrEmpty(userInn)) {
            req.append("<i OKPO='").append(userInn).append("' />");
        } else if (!nullOrEmpty(userPhone)) {
            req.append("<i PhoneM='").append(userPhone).append("' />");
        } else {
            throw new IllegalArgumentException("All parameters cannot be NULL or empty");
        }

        req.append("<o>");
        /*ArrayList userInfoFieldList = getUserInfoFieldList();
        for (Object anUserInfoFieldList : userInfoFieldList) {
            String f = (String) anUserInfoFieldList;
            req.append("<").append(f).append("/>");
        }*/
        req.append("</o>");
        req.append("</r>");
        req.append("</doc>");
        return req.toString();
    }

    private static boolean nullOrEmpty(String str) {
        String rezult = str == null ? "" : str;
        return rezult.equals("") || rezult.isEmpty();
    }
}
